package com.swotplus.admin.web.system;

import com.swotplus.framework.web.BaseController;
import com.swotplus.common.core.AjaxResult;
import com.swotplus.common.core.MenuInfo;
import com.swotplus.framework.shiro.ShiroUtils;
import com.swotplus.system.sys.entity.*;
import com.swotplus.system.sys.service.SysMenuService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.ArrayList;
import java.util.List;

/**
 *
 * @author hugang
 * @since 2020-04-11
 */
@Controller
public class SysIndexController extends BaseController {
    @Autowired
    private SysMenuService sysMenuService;


    /**
     *     系统首页
     */

    @RequestMapping({"/","/index"})
    public String index(ModelMap mmap)
    {
        // 取身份信息
        SysUser sysUser = ShiroUtils.getSysUser();
        //获取顶级目录菜单信息
        List<SysMenu> sysMenus=sysMenuService.selectMenuAll(sysUser.getId());
        mmap.put("sysMenus",sysMenus);
        return "index";
    }

    /**
     * 系统首页内容介绍
     */
    @GetMapping("/main")
    public String main(ModelMap mmap)
    {
        return "main";
    }


    /**
     *   根据目录id获取左侧菜单
     */
    @RequestMapping("/menu/left")
    @ResponseBody
    public AjaxResult getMenuInfoList(@RequestParam("code") String code){
        List<SysMenu> menuInfoList = new ArrayList<>();
        //获取当前用户角色信息
        SysUser sysUser = this.getUserInfo();
        List<MenuInfo> sysMenuList=sysMenuService.selectMenusByUserId(code,sysUser.getId());
        return AjaxResult.success(sysMenuList);
    }


}
